﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<ScrumTime.Models.HelpModel>" %>


<script runat="server">
    private ScrumTime.Models.Help getHelp(int id, ScrumTime.Models.ScrumTimeEntities _ScrumTimeEntities)
    {
        ScrumTime.Models.Help resultado = null;

        var results = from t in _ScrumTimeEntities.Helps
                      where t.HelpId == id
                      select t;
        if (results.Count() > 0)
            resultado = results.First<ScrumTime.Models.Help>();        
        
        return resultado;
    }

    private List<ScrumTime.Models.OldHelpData> getOldHelpData(int HelpId, ScrumTime.Models.ScrumTimeEntities _ScrumTimeEntities) {
        var results = from t in _ScrumTimeEntities.OldHelpDatas
                      where t.HelpId == HelpId && t.type== Model.type
                      orderby t.Orden ascending
                      select t;                
        return results.ToList();
    }

    private List<ScrumTime.Models.NewHelpData> getNewHelpData(int HelpId, ScrumTime.Models.ScrumTimeEntities _ScrumTimeEntities)
    {
        var results = from t in _ScrumTimeEntities.NewHelpDatas
                      where t.HelpId == HelpId && t.type == Model.type
                      orderby t.Orden ascending
                      select t;
        return results.ToList();
    }
    
</script>

<%
    ScrumTime.Models.ScrumTimeEntities _ScrumTimeEntities = new ScrumTime.Models.ScrumTimeEntities();
    
    ScrumTime.Models.Help help = getHelp( Model.HelpId, _ScrumTimeEntities);

    List<ScrumTime.Models.NewHelpData> newHelpData = getNewHelpData(Model.HelpId, _ScrumTimeEntities);
    List<ScrumTime.Models.OldHelpData> oldHelpData = getOldHelpData(Model.HelpId, _ScrumTimeEntities);
           
%>

<table width="100%">
    <tr>
        <td colspan="2">
            <literal style="font-weight:bold"> 
                Story Name:
            </literal>
            &nbsp<%: help.UserStoryName %>
        </td>
    </tr>
    <tr style="display:none">
        <td colspan="2">
            <literal style="font-weight:bold"> 
                Description Old:
            </literal>
             &nbsp<%: help.Description1 %>
        </td>
    </tr>
    <tr>
        <td colspan="2">
            <literal style="font-weight:bold"> 
                Description New:
            </literal>
            &nbsp<%: help.Description1 %>
        </td>
    </tr>
    <tr>
        <td style="display:none"font-weight:bold">
            <% if (Model.type == "task")
               { 
            %>
                Old Tasks
            <%
                }
               else
               {
            %>
                Old Acceptance Criteria            
            <%   
               } 
            %>
            
        </td >
        <td colspan="2" style="font-weight:bold">
            <% if (Model.type == "task")
               { 
            %>
            Tasks
            <%
                }
               else
               {
            %>
             Acceptance Criteria           
            <%   
               } 
            %>
            
        </td>
    </tr>
    <% 
        int contador = 0;

        while (contador < oldHelpData.Count || contador < newHelpData.Count)
        {
    %>
    <tr>
        <td style="display:none">
            <% if (contador < oldHelpData.Count)
               { 
            %>
                <%: oldHelpData.ElementAt(contador).Description%>
            <%           
               } 
            %>
            
        </td>
        <td colspan="2" style="border-style:solid; border-width:1px;">
            <% if (contador < newHelpData.Count)
               {
                   String colorFuente = "black";

                   //bool mark =  help.NewHelpDatas.ElementAt(contador).mark;
                   if (newHelpData.ElementAt(contador).mark)
                   {
                       colorFuente = "red";
                   }
            %>
              <span style="color:<%:colorFuente%>">
                <%: newHelpData.ElementAt(contador).Description%>
              </span>                            
            <%           
               } 
            %>
        </td>
    </tr>
    <%
        contador++;
        } 
    %>
</table>